<template>
  <div class="todo-footer">
    <label>
      <input type="checkbox"
             v-model="selectAll"
      />
    </label>
    <span>
          <span>Finished<i style="color:red;font-size: 20px">{{checkedCount}}</i></span> of <i style="color:green;font-size: 20px">{{todos.length}}</i>
        </span>
    <button class="btn btn-danger"
            v-show="checkedCount"
            @click="deleteChecked"
    >Delete Selected</button>
  </div>
</template>

<script>
  export default {
    name: "todo-footer",
    props:{
      todos: Array
    },
    computed:{
      checkedCount(){
        return this.todos.reduce((accumulator,currentTodo)=>{
          var val = currentTodo.completed?1:0
          return accumulator + val
        },0)
      },
      selectAll:{
        get(){
          return (this.todos.length === this.checkedCount)&&(this.todos.length)
        },
        set(val){
          this.$emit("selectAll",val)
        }
      }
    },
    methods:{
      deleteChecked(){
        this.$emit("deleteChecked")
      }
    }
  }
</script>

<style scoped>
  .todo-footer {
    height: 40px;
    line-height: 40px;
    padding-left: 6px;
    margin-top: 5px;
  }
  
  .todo-footer label {
    display: inline-block;
    margin-right: 20px;
    cursor: pointer;
  }
  
  .todo-footer label input {
    position: relative;
    top: -1px;
    vertical-align: middle;
    margin-right: 5px;
  }
  
  .todo-footer button {
    float: right;
    margin-top: 5px;
  }

</style>
